<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div id="app">
      {{words}}
      <button @click="words+='~'">修改words</button>
      {{obj.words}}
      <button @click="obj.age+=1">修改words</button>
    </div>

    <!-- 引入vue -->
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          words: "苹果",
          obj: {
            words: "苹果",
            age: 18,
          },
        },
        computed: {},
        methods: {},
        watch: {
          // 监听基本数据类型--可以简写
          words(newVal, oldVal) {
            console.log(newVal, oldVal);
          },
          // 复杂数据类型要开启深度监听
          obj: {
            handler(newVal, oldVal) {
              console.log(newVal, oldVal);
            },
            // 开启深度监听
            deep: true,
            //立即执行
            immediate: true,
          },
        },
      });
    </script>
  </body>
</html>
